<template>
    <h1>投资项目列表</h1>

    项目名称:<input type="text" v-model="Name">
    投资总额度:<input type="text" v-model="MinMoney">-
    <input type="text" v-model="MaxMoney">
    <input type="button" value="查询" @click="ShowInvest">

    <table>
        <thead>
            <tr>
                <th>投资名称</th>
                <th>投资总额度</th>
                <th>已投资额度</th>
                <th>剩余额度</th>
                <th>投资人数</th>
                <th>操作</th>
            </tr>
        </thead>

        <tbody>
            <tr v-for="item in Info">
                <td>{{ item.I_Name }}</td>
                <td>{{ item.I_SumMoney }}</td>
                <td>{{ item.I_YMoney }}</td>
                <td>{{ item.I_SMoney }}</td>
                <td>{{ item.I_Count }}</td>
                <td>
                    <input type="button" value="删除" @click="DelData(item.I_Id)" >
                    <input type="button" value="修改" @click="Jump(item.I_Id)" >
                </td>
            </tr>
        </tbody>

    </table>

</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter();

const Info = ref([{
    I_Id:'',
    I_Name:'',
    I_SumMoney:'',
    I_YMoney:'',
    I_SMoney:'',
    I_Count:''
}])

const Name = ref('');
const MinMoney = ref('');
const MaxMoney = ref('');

onMounted(()=>{
    ShowInvest();
})

const ShowInvest = () => {
    axios({
        method: 'get',
        url: 'http://localhost:51401/api/Invest/ShowInvest',
        params:{
            Name:Name.value,
            MinMoney:MinMoney.value,
            MaxMoney:MaxMoney.value
        }
    })
    .then(function (res) {
        console.log(res.data);
        Info.value = res.data;
    })
    .catch(function (err) {
        console.log(err);
    });
} 

const DelData = (Id:string)=>{
    axios({
        method:'get',
        url:'http://localhost:51401/api/Invest/DelData',
        params:{
            Id:Id
        }
    })
    .then(function (res) {
        if(res.data>0){
            alert('删除成功');
            ShowInvest();
        }
        else{
            alert('删除失败');
            ShowInvest();
        }
    })
    .catch(function (err) {
        console.log(err);
    })
}

const Jump = (Id:string)=>{
    router.push({
        name:'EditInvest',
        params:{
            Id:Id
        }
    })
}

</script>